# Maintainer: Antonio Rojas <arojas@archlinux.org>

pkgname=jupyterlab
_pipname=jupyterlab
pkgver=3.6.3
pkgrel=7
pkgdesc='JupyterLab computational environment'
arch=(any)
url='https://github.com/jupyterlab/jupyterlab'
license=(custom)
makedepends=(python-build python-installer python-pre-commit)
depends=(python-jupyterlab_server python-jupyter_packaging jupyter-notebook-shim jupyter-server-ydoc nodejs)
optdepends=('npm: to install extensions' 'jupyterlab-widgets: ipywidgets support')
checkdepends=(python-pytest-tornasync python-pytest-jupyter npm)
source=(https://pypi.io/packages/source/${_pipname:0:1}/$_pipname/$_pipname-$pkgver.tar.gz
        no-nbclassic.patch)
sha256sums=('373e9cfb8a72edd294be14f16662563a220cecf0fb26de7aab1af9a29b689b82'
            'c06dc4b2bc712e7fbffe9850a9c99f98ee4f5210ecd3a9572b7ed21496c8d59e')

prepare() {
  patch -d $pkgname-$pkgver -p1 < no-nbclassic.patch # Drop nbclassic dependency
  sed -e '/nbclassic/d' -e '/notebook<7/d' -e 's|ydoc\~\=.*|ydoc|g' -i $pkgname-$pkgver/setup.cfg
}

build() {
  cd $pkgname-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  cd $pkgname-$pkgver
  pytest -v -k 'not test_build and not test_announcements'
}

package() {
  cd $pkgname-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  mv "$pkgdir"/usr/etc "$pkgdir"

  install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
